const TransformPages = require('uni-read-pages')
const {
	webpack
} = new TransformPages()
let filePath = ''
let Timestamp = ''
//编译环境判断,判断是否H5环境
if (process.env.UNI_PLATFORM === 'h5') {
	filePath = 'static/js/'; //打包文件存放文件夹路径
	Timestamp = '.' + new Date().getTime(); //时间戳
}
module.exports = {
	configureWebpack: {
		plugins: [
			new webpack.DefinePlugin({
				ROUTES: webpack.DefinePlugin.runtimeValue(() => {
					const tfPages = new TransformPages({
						includes: ['path', 'name', 'aliasPath', 'meta']
					});
					return JSON.stringify(tfPages.routes)
				}, true)
			})
		],
		output: { // 输出重构  打包编译后的 文件目录 文件名称 【模块名称.时间戳】
			filename: `${filePath}[name]${Timestamp}.js`,
			chunkFilename: `${filePath}[name]${Timestamp}.js`
		}
	}
}